package com.zr.gdms.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.zr.gdms.service.CourseService;
import com.zr.gdms.serviceimpl.CourseServiceImpl;

/**
 * @author  shichongming
 * @E-mail: 
 * @date 创建时间：2017年6月2日 上午10:11:02 
 * @version 1.0 
 * @parameter  
 * @since  
 * @return  
 */

public class SearchCoureByTnameControllerSCM extends HttpServlet{
	CourseService cs=new CourseServiceImpl();
	
	//根据教师的信息查询课题
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {	
	doPost(req, resp);
}
@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		HttpSession session=req.getSession();
		String teacherinfo=req.getParameter("info");
	
		int  rows=Integer.parseInt(req.getParameter("rows"));
	
		int  p=Integer.parseInt(req.getParameter("page"));
	
		int page=(p-1)*rows;
		//根据教师信息查出总数进行分页
		int total = cs.sgetCountsCourseByTeacherInformation(teacherinfo);
		
		//根据教师信息分页查询
		JSONArray js=cs.sfindCourseByTeacherInformation(teacherinfo, page, rows);
		
		//创建json对象
		JSONObject j=new JSONObject();
		j.put("total", total);
		j.put("rows",js);
		//创建输出流对象
		PrintWriter pw =resp.getWriter();
		pw.write(j.toString());
		
		
		
		
	}
}
